package edu.cornell.lsi.util;

// User Session class. Holds the session data values for a session
public class UserSession {

	private String session;
	private String versionID;
	private String timestamp;
	private int counter;
	private String value;
	private boolean inUse;

	//Constructor. Set the parameters
	public UserSession(String session, String versionId, String timestamp, int counter, String value){

		this.session = session;
		this.versionID = versionId;
		this.timestamp = timestamp;
		this.counter = counter;
		this.value = value;
	}

	//Getter methods for class variables
	public String getSession(){
		String copySession = this.session;
		return copySession;
	}
	public String getversionID(){
		String copyVersion = this.versionID;
		return copyVersion;
	}
	public String getDate(){
		String copyDate = this.timestamp;
		return copyDate;
	}
	public int getCounter(){
		int copyCounter = this.counter;
		return copyCounter;
	}

	public String getValue(){
		String copyValue = this.value;
		return copyValue;
	}

	// returns true if one thread is updating an object of this class
	public boolean isInUse(){
		return this.inUse;
	}

	// synchronized update method 
	public void update(String versionId, String timestamp, int counter, String value){
		this.inUse = true;
		if(versionId!= null) this.versionID = versionId;
		if(timestamp!= null) this.timestamp = timestamp;
		this.counter = counter;
		if(value != null) this.value = value;
		this.inUse = false;
	}

}
